package com.estate.house.controller;

import com.estate.bean.House;
import com.estate.bean.Owner;
import com.estate.house.service.HouseService;
import com.estate.util.JsonResult;
import com.estate.util.ResultTool;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/house")
public class HouseController {
    @Resource
    private HouseService houseService;

    @GetMapping("/list/{houseId}")
    public JsonResult findById(@PathVariable("houseId") String houseId) {
        return houseService.findById(houseId);
    }


    @GetMapping("/listByPage/{page}/{size}")
    public JsonResult listByPage(@PathVariable("page") int page, @PathVariable("size") int size) {
        log.info("page:{},size:{}", page, size);
        JsonResult result = houseService.listByPage(page, size);
        log.info("result:{}", result);
        return result;
    }

    @PostMapping("/save")
    public JsonResult save(House house) {
        log.info("house:{}", house);
        JsonResult result = houseService.addHouse(house);
        log.info("result:{}", result);
        return result;
    }

    @PutMapping("/update")
    public JsonResult update(House house) {
        log.info("house:{}", house);
        JsonResult result = houseService.updateHouse(house);
        log.info("result:{}", result);
        return result;
    }

    @DeleteMapping("/delete")
    public JsonResult delete(@RequestParam("id") String id) {
        log.info("id:{}", id);
        return houseService.deleteHouse(id);
    }
}
